<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="com.sdry.model.zc.ZcSysUserEntity" %>
<% 
	ZcSysUserEntity zcSysUserEntity =  (ZcSysUserEntity)request.getSession().getAttribute("user");
	//String roleId = zcSysUserEntity.getRoleId(); 
	//String roleIds[] = roleId.split(",");
	String roleName = zcSysUserEntity.getRoleName(); 
	String roleNames[] = roleName.split(",");
	boolean isAdmin= false;
	/* for(int i =0;i<roleIds.length;i++){
		if("2".equals(roleIds[i])){
			isAdmin = true;
		}
	} */
	for(int i =0;i<roleNames.length;i++){
		if("管理员".equals(roleNames[i])|| "超级管理员".equals(roleNames[i])){
			isAdmin = true;
		}
	}
%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>库存管理最新</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<jsp:include page="${pageContext.request.contextPath }/resource_path.jsp" flush="true"/>
	<link rel="stylesheet" media="all" href="${pageContext.request.contextPath }/assets/formSelects/formSelects-v4.css">
	<link rel="stylesheet" media="all" href="${pageContext.request.contextPath }/assets/formSelects/formSelects-v4.js">
	<style type="text/css">
		.layui-table-view .layui-table-body tr.table_tr_click {
	      background-color: pink;
	    }
	</style>
</head>
<body class="layui-anim layui-anim-up">
	<div class="x-nav">
		<span class="layui-breadcrumb">
  			<a href="">首页</a>
			<a>
				<cite>库存管理</cite>
			</a>
		</span>
    </div>
	<div class="x-body">
		<div class="layui-row">
			<div class="layui-form">
				<div class="layui-input-inline">
					<div class="layui-input-inline" style="width: 285px">
						<select style="width: 285px" class="" name="keyword" id="keyword" lay-filter="keyword">
							<option value="">--请选择供应商--</option>
							<c:forEach items="${allCustomerList }" var="customer">
								<option value="${customer.id}">${customer.customer_name }</option>
							</c:forEach>
						</select>
					</div>
					<div class="layui-input-inline" style="width: 150px">
						<input class="layui-input" id="keyword2" placeholder="请输入产品码查询" style="width: 150px">
					</div>
				</div>

				<button class="layui-btn layui-btn-normal" data-type="reload"><i class="layui-icon layui-icon-search"></i>检索</button>
			 <button class="layui-btn layui-btn-danger" id="export"><i class="layui-icon layui-icon-upload"></i>导出</button> </div>
		</div>

		
		<div id = "fDiv">
			<table class="layui-hide" id="inventoryInfoList" lay-filter="inventoryInfoList"></table>
		</div>
		<div id = "details">
			<table class="layui-hide" id="inventoryInfoListDetails" lay-filter="inventoryInfoListDetails"></table>
		</div>

	</div>

	<script>
		//全局定义一次, 加载formSelects
		layui.config({
			base: '${pageContext.request.contextPath }/assets/formSelects/' //此处路径请自行处理, 可以使用绝对路径
		}).extend({
			formSelects: 'formSelects-v4'
		});


		layui.use(['table','layer','upload','form','laydate','formSelects'], function(){
			var table = layui.table;
			var layer = layui.layer;
			var form = layui.form;
			var laydate = layui.laydate;
			var formSelects = layui.formSelects;

			var $ = layui.jquery, active = {
				reload:function () {
					var keyword = $("#keyword").val();
					var keyword2 = $("#keyword2").val();
					/*keyword2 = "'%"+keyword2+"%'";
					var strWhere = "";
					if(keyword!="" && keyword2 != "''"){
						strWhere = 'm.customer_id = '+keyword+' and m.materiel_num like '+keyword2+' and ';
					}else if(keyword!="" && keyword2 == "''"){
						strWhere = 'm.customer_id = '+keyword+' and ';
					}else if(keyword=="" && keyword2 != "''"){
						strWhere = 'm.materiel_num like '+keyword2+' and ';
					}else{
						strWhere = ' ';
					}*/
					table.reload('contenttable',{
						method:'get',
						where:{
							"customerId":keyword,
							"maNum":keyword2

						}
						,page: {
							curr: 1//重新从第 1 页开始
						}
					});

					table.reload('tiaoMaList',{
						method:'get',
						where:{

						}
						,page: {
							curr: 1//重新从第 1 页开始
						}
					});
				}
			}

			$("#export").click(function(){
				window.location.href="${pageContext.request.contextPath}/inventoryManagement/doExportall.do";
			})
			$('.layui-btn').on('click', function(){
				var type = $(this).data('type');
				active[type] ? active[type].call(this) : '';
			});
			table.render({
				elem: '#inventoryInfoList'
				,url:'${pageContext.request.contextPath }/stock/getStockList.do'
				,title: '库存列表'
				,id :'contenttable'
				,toolbar: '#toolbarDemo'
				,limits:[10,20,30]
				,skin: 'row'
				,even: true
				,cols: [[
					{type: 'checkbox', fixed: 'left'}
					,{field:'', title:'序号', sort: true, type:'numbers', width: 60}
					,{field:'customer', title:'供应商',width:140,templet:function(row){
							if(row.materiel.customer!=null){
								return row.materiel.customer.customer_name;
							}else{
								return "";
							}
						}}
					,{field:'materiel_name', title:'物料名称',templet:function(row){
							if(row.materiel!=null){
								return row.materiel.materiel_name;
							}else{
								return "";
							}
						}}
					,{field:'materiel_num', title:'产品码',width:190,templet:function(row){
							if(row.materiel!=null){
								return row.materiel.materiel_num;
							}else{
								return "";
							}
						}}
					,{field:'unit', title:'单位',width:80,templet:function(row){

							if(row.materiel.unit != null){
								return row.materiel.unit;
							}else{
								return "";
							}
						}}

					,{field:'mNum', title:'数量',width:80}
					,{field:'countAll', title:'总库存',width:90}
					,{field:'upper_value', title:'库存上限',width:90,templet:function(row){
							if(row.materiel!=null){
								return row.materiel.upper_value;
							}else{
								return "";
							}
						}}
					,{field:'lower_value', title:'库存下限',width:90,templet:function(row){
							if(row.materiel!=null){
								return row.materiel.lower_value;
							}else{
								return "";
							}
						}}
					,{field:'region', title:'所属库区',templet:function(row){
							if(row.materiel.region!=null){
								return row.materiel.region.region_name;
							}else{
								return "";
							}
						}}
					/*,{field:'enterDate',width:120, title:'入库日期',templet:function(row){
                            return row.enterDate.substr(0,16)
                        }}
                    ,{field:'userName',width:120, title:'入库人',templet:function(row){
                            if(row.zcSysUser!=null){
                                return row.zcSysUser.userName;
                            }else{
                                return "";
                            }
                        }}*/
				]]
				,response: {   //如果无需自定义数据响应名称，可不加该参数
					countName: 'total' //规定数据总数的字段名称，默认：count
					,dataName: 'rows' //规定数据列表的字段名称，默认：data
				}
				,page: true
				,done:function(res, curr, count){

					$('th').css({
						'background-color': '#009688', 'color': '#fff','font-weight':'bold',
					})
				}
			});
			//监听行单击事件
			table.on('row(inventoryInfoList)', function(obj){

				var mid = obj.data.id;
				//mBatch = obj.data.mBatch;
				//time = obj.data.enterDate.substr(0,16);
				//man = obj.data.zcSysUser.userName;

				table.render({
					elem: '#inventoryInfoListDetails'
					,url:'${pageContext.request.contextPath }/stock/getTiaoMaList.do?mid='+mid
					,title: '库存详情列表'
					,limits:[10,20,30]
					,id :'tiaoMaList'
					,skin: 'row'
					/*,even: true*/
					,cols: [[
						{title:'序号', sort: true, width: 60, type:'numbers', align:'center'},
						{field:'materiel_num', title: '条码', align:'center'},
						{field:'unit', title: '数量', align:'center'},
						// {field:'brevity_num', title: '入库人', align:'center'},
						{field:'out_date', title: '入库时间', align:'center'}
					]]
					,page: true
					,request: {   //如果无需自定义请求参数，可不加该参数
						pageName: 'page' //页码的参数名称，默认：page
						,limitName: 'pageSize' //每页数据量的参数名，默认：limit
					}
					,response: {   //如果无需自定义数据响应名称，可不加该参数
						countName: 'total' //规定数据总数的字段名称，默认：count
						,dataName: 'rows' //规定数据列表的字段名称，默认：data
					}
					,done:function(res, curr, count){
						//mergeDetails(res);
						$('th').css({
							'background-color': '#009688', 'color': '#fff','font-weight':'bold',
						})
					}
				})
			});
		})
	</script>
</body>
</html>
